import { TaskDetailInfo, WeekDay } from 'admin/schema/Task';
import { Checkbox, Form, Switch } from 'antd';
import React from 'react';
import {
  callTimeOptions,
  getAllowTimes,
  getLabelName,
  monthsData,
  weeksData,
} from '../../components/TaskTool';

interface IProps {
  formData: TaskDetailInfo;
}
/* 呼叫规则 */
const CallRules: React.FC<IProps> = ({
  formData: { dateBegin, expireDate, execTime, skipHolidays, allowTimes },
}) => {
  return (
    <div className="call-rules">
      <Form
        layout="horizontal"
        initialValues={{
          dateBegin,
          expireDate,
          execTime,
          skipHolidays: skipHolidays === 'on' ? true : false,
        }}
      >
        <Form.Item label="任务有效期">
          {dateBegin}-{expireDate ? expireDate : ''}
        </Form.Item>
        {execTime && (
          <Form.Item label="执行时间">
            <div className="time-type">{getLabelName(callTimeOptions, execTime.type)}</div>
            {execTime.type === 'weekly' && (
              <Form.Item name={['execTime', 'weeks']}>
                <Checkbox.Group className="checkbox-day-group">
                  {weeksData.map(tag => (
                    <Checkbox key={tag} value={tag} disabled>
                      {WeekDay[tag]}
                    </Checkbox>
                  ))}
                </Checkbox.Group>
              </Form.Item>
            )}
            {execTime.type === 'monthly' && (
              <Form.Item name={['execTime', 'months']}>
                <Checkbox.Group className="checkbox-day-group">
                  {monthsData.map((tag, index) => (
                    <Checkbox key={tag} value={tag} disabled>
                      {tag}
                    </Checkbox>
                  ))}
                </Checkbox.Group>
              </Form.Item>
            )}
          </Form.Item>
        )}
        {skipHolidays && (
          <Form.Item label="节假日不外呼" name="skipHolidays" valuePropName="checked">
            <Switch disabled />
          </Form.Item>
        )}
        <Form.Item label="呼叫时间">{getAllowTimes(allowTimes)}</Form.Item>
      </Form>
    </div>
  );
};

export default CallRules;
